package io.mycat.encrypt.constant;

/**
 * 数据库类型
 *
 * @author yuwei
 * @since 2020-03-14
 */
public enum DbType {

	/**
	 * MYSQL
	 */
	MYSQL("1", "MySql数据库", "jdbc:mysql://${host}:${port}/${dbName}?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8","com.mysql.jdbc.Driver"),
	/**
	 * MARIADB
	 */
	MARIADB("2", "MariaDB数据库", "jdbc:mariadb://${host}:${port}/${dbName}",""),
	/**
	 * ORACLE
	 */
	ORACLE("3", "Oracle11g及以下数据库", "jdbc:oracle:thin:@${host}:${port}:${sid}","oracle.jdbc.driver.OracleDriver"),
	/**
	 * oracle12c new pagination
	 */
	ORACLE_12C("4", "Oracle12c+数据库", "jdbc:oracle:thin:@${host}:${port}:${sid}","oracle.jdbc.driver.OracleDriver"),
	/**
	 * POSTGRESQL
	 */
	POSTGRE_SQL("5", "PostgreSql数据库", "jdbc:postgresql://${host}:${port}/${dbName}",""),
	/**
	 * SQLSERVER2005
	 */
	SQL_SERVER2008("6", "SQLServer2008及以下数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}",""),
	/**
	 * SQLSERVER
	 */
	SQL_SERVER("7", "SQLServer2012+数据库", "jdbc:sqlserver://${host}:${port};DatabaseName=${dbName}",""),
	/**
	 * UNKONWN DB
	 */
	OTHER("8", "其他数据库", "",""),

	/**
	 * TIDB数据库（数仓用）
	 */
	TIDB("9", "TIDB数据库", "jdbc:mysql://${host}:${port}/${dbName}?characterEncoding=utf8&useSSL=false&useServerPrepStmts=true&prepStmtCacheSqlLimit=10000000000&useConfigs=maxPerformance&rewriteBatchedStatements=true&defaultfetchsize=-214783648","com.mysql.jdbc.Driver");

	/**
	 * 数据库名称
	 */
	private final String db;

	/**
	 * 描述
	 */
	private final String desc;

	/**
	 * url
	 */
	private final String url;

	/**
	 * url
	 */
	private final String driveClassName;

	public String getDb() {
		return this.db;
	}

	public String getDesc() {
		return this.desc;
	}

	public String getUrl() {
		return this.url;
	}

	public String getDriveClassName() {
		return driveClassName;
	}

	DbType(String db, String desc, String url, String driveClassName) {
		this.db = db;
		this.desc = desc;
		this.url = url;
		this.driveClassName = driveClassName;
	}

	/**
	 * 获取数据库类型
	 *
	 * @param dbType 数据库类型字符串
	 */
	public static DbType getDbType(String dbType) {
		for (DbType type : DbType.values()) {
			if (type.db.equals(dbType)) {
				return type;
			}
		}
		return OTHER;
	}
}
